The question was "WHY" did God create the devil.

It's the same kind of question as "Why did God choose me and not my friend." There's no real answer. But we do get a hint of why there is evil, a devil, and sin.

God wants His glory known by all His creatures. His mercy is glorious, His hatred of sin is glorious, His justice is glorious. We would know none of these aspects of God's glory without sin, and without a devil.

Romans 9:14-23