It is most important to test all ideas by examining the Bible to see whether or not they are in accordance with God’s revealed Truth. Omniscience is not being claimed by the author of these thoughts!
God created the world perfect. Sadly, sin entered into this earthly paradise when mankind succumbed to the temptation of the Devil appearing in the guise of a serpent. By disobeying God, Adam and Eve started a chain of events which soon reached the unacceptable level of murder. Looking at today’s world, such things and worse still happen, causing great distress.
Without the entrance of sin, the world would presumably have remained perfect. If God had not created Satan, Adam and Eve would not have been tempted into disobedience. Why, then, did God create the Devil and allow him to rebel?
Only God can answer that, of course. But we, being fashioned in his image, having the ability to think and communicate with our Maker, might make intelligent guesses. Here is a suggestion:

Let us consider the circle shown in Fig. 1 on the right. It is a bright object that is inherently beautiful. Admire the perfection of its symmetry and the graceful sweep of its circumference. Appreciate the brilliance of its white coloration. Observe its area and its boundary. “What circle?” you ask. “I can see only a square.” But there is a circle, I assure you, which is every bit as real as the square you are seeing so clearly. The circle is, in fact, closer to you than the square!
Now let us consider the circle in Fig. 2 again shown on the right. It is an exact copy of Fig. 1 except in one respect – the square has been coloured black. Our circle is a bright object that is inherently beautiful. Admire the perfection of its symmetry and the graceful sweep of its circumference. Appreciate the brilliance of its white coloration. Observe its area and its boundary. Ah! This time you can.
Now consider God, the great creator of all things, before the advent of the universe and this world as we know it. Not only has he populated heaven with the spiritual beings we know as angels, but he has their constant worship and full obedience. If this were the sum of creation, it would be rather like the case of Fig. 1 above, everything being without variation and having no distinctions. The angels would be little more than spiritual robots, making their worship and praise of little real value. Everything is goodness and light, and anything so uniform is rapidly taken for granted.
Coming to the crux of the matter, it was necessary for a contrast to God’s nature to exist in order that his goodness might be truly appreciated. (cf. Fig. 2). Hence, the Devil was allowed to rebel, probably with other angels who became the demons that follow and worship Satan. An empire of evil was established which opposes God, but ultimately has no hope of overcoming the supreme potentate of the spiritual world. Like it or not, the whole of mankind is involved in this spiritual battle, with each individual being on one side or the other. God created us in the knowledge that the whole human race would, by fallen nature, despise, ignore, blaspheme or reject its Lord and Master.
Thankfully, God is merciful to those who turn to him. Such will be able to worship him meaningfully now and in the new heavens, knowing not only good and evil, but also the consequences of each.
Whether the need for contrast is the reason behind the origin of the Devil I cannot tell, but it makes some sort of sense to me. You must make up your own mind. Whatever you think, please keep asking questions and seeking the answer in God’s revealed truth. The Bible has all the crucial answers if you only dig deep enough and think things through.