To cut a very very long story short:
In the Old Testament, satan was an angel who did the bidding of God
and wasn't exactly considered good or bad.
The creation of satan was mainly to explain the dual nature of
God.
Back then in the times of the OT, the Israelites believed that the
one true god was Yahweh (there were many other gods that other
tribes worshipped) and that He was infinitely good. However, they
also acknowledged that bad and evil things did happen (eg, wars
with other tribes, death, murder, famine etc) to them and they had
to explain why this was so. Since they believed that Yahweh was
omnipotent (almighty and all knowing) and was "good" by nature,
they had to explain where this "evil" came from. And since there
cannot be another "god" (they believed there was only ONE true
God), satan was created by the OT writers for this purpose. Note
that satan was part of God and had to do God's bidding eg to
inflict harm onto Job, satan had to ask God for permission before
it could do anything.
However, the role of the devil/satan evolved over the years. By the
time of the New Testament, the role of the devil/satan was one of
opposition to God.
Jesus Christ came to save humanity from sin/evil and these were
attributed to temptations from the devil. Hence, the devil slowly
became a separate entity from God (as opposed to its role in the
OT).
This is just a very brief and simplistic explanation. If you have
any questions, you might want to check with your local priest/
pastor to provide a clearer picture.
Hope this helps.

T