The Bible doesn't specifically tell us why God created the devil and the other demons. However, it makes clear that He has every right to do as He sees fit, given His perfect wisdom, perfect power, and perfect love.
The Book of Romans describes God's creation, including the devil and demons, as clay in the hands of the potter, and demonstrates by analogy that just as the potter has complete license over His creation, so does God over His.
Rom 9:21-24 - Does not the potter have power over the clay, from the same lump to make one vessel for honor and another for dishonor? What if God, wanting to show His wrath and to make His power known, endured with much longsuffering the vessels of wrath prepared for destruction, and that He might make known the riches of His glory on the vessels of mercy, which He had prepared beforehand for glory, even us whom He called, not of the Jews only, but also of the Gentiles? (NKJV)
Applying these verses to the devil and other fallen angels, it is entirely possible that God created them for the express purpose of making known the riches of His glory to those He has prepared for His mercy.
Good appears so much better when compared with evil.
The Bible further teaches that without regeneration by the Holy Spirit of God, each of us is likewise destined for destruction. Romans 3:23 tells us that all have sinned and fallen short of the glory of God. Romans 6:23 tells us that what we have earned from that sin is death. However, it goes on to say that the free gift of God is eternal life through Christ Jesus. Jesus Himself tells us in John 14:6 that He is the Way, the Truth, and the Life, and that no one comes to the Father but by Him.
According to Romans 10:9, if you confess with your mouth that Jesus Christ is Lord and believe in your heart that God raised Him from the dead, you will be saved.
If you have never accepted Jesus Christ as Lord of your life, now would be a good time to do so (2 Corinthians 6:2).