We don't know!
Unfortunately, the Bible doesn't tell us why he created the world, simply that he did create it.
Lonely
One speculation (and it is pure speculation) is that he created the world in order to have other beings with free will that would love him. We can see this in the fact that there are things we can do to please God. From that concept, we can expand it a bit to assume that the things he finds pleasing is the reason that he actually created us. So, in essence, the speculation is that he created us so that we could love him and choose to follow him.
Self-glorification
Another theory (eg speculation) is that he wanted to bring glory to himself. The argument goes that all created things reflect God's glory (per Psalm 19:1 for example), in particular mankind (per Genesis 1:26); since the creation reflects His glory, then he must have created them for the purpose of reflecting his glory.
The problem with these theories is that they use the process of logical induction to come to these conclusions. In fact these thoughts are a very weak induction. It's like saying "I've only seen a green frog, therefore all frogs must be green."
These theories attempt to attribute thoughts to God based on our understanding of his creation. This, in my opinion, is a very dangerous road.
Summary (TL;DR)
We don't know why God created the world because he never told us. We do have ideas including the two I mentioned above. However, these ideas, as I mentioned, are pure speculation and we must be careful not to presume that we know the mind of God.
Isaiah 55:8 NWT
“For the thoughts of YOU people are not my thoughts, nor are my ways YOUR ways,” is the utterance of Jehovah.