The Bible doesn't tell us exactly why God created the angelic being who would one day become the one it calls Satan (which means "Adversary" a vivid description of his purpose).
It does, however, hint to us that this powerful angel to whom God had given great authority became filled with pride, and one day before time began he decided he would lead a revolt against God and try to take God's place. He apparently tried to convince the other angels to join him in his revolt and because they had a free will, some of them chose to follow him.
But the revolt failed, and Satan was cast out of heaven. From that point on, Satan would forever stand opposed to God and try to block His work at every opportunity. The Bible says, "How you have fallen from heaven, O morning star. ... You said in your heart, 'I will ascend to heaven; I will raise my throne above the stars of God'" (Isaiah 14:12-13). Satan's greatest victory was when he led Adam and Eve astray, bringing sin and death to the whole human race.
But listen: Satan is a defeated foe! By His death and resurrection Jesus Christ conquered death and Hell and Satan! And someday that victory will be complete, and "the devil, who deceived them, (will be) thrown into the lake of burning sulfur" (Revelation 20:10). Until that day, make it your goal to live for Christ and walk close to Him every day.