Why did God need to plant the tree of knowledge of good and evil in the garden of Eden in the first place? Why did God need to plant the tree of knowledge of good and evil in the garden of Eden in the first place?

I mean Mormons say that God was in fact having a hidden desire for Adam and Eve to disobey His words and partake of that tree so that they could later be tested in the midst of sinful world whether they would seek God or merely enjoy the worldly pleasures. 

When I confronted one Mormon on this point by saying that it seems a bit contradictory for God to have forbidden Adam and Eve to do something that He in fact wanted them to do, he confronted me with this question: otherwise, why do you think God planted that tree in the garden of Eden while He didn't want Adam and Eve to partake of that tree?
I believe that your question is very closely related to the one of "How could an omnipotent God who hates sin allow sin?  If He's omnipotent, couldn't He have prevented us from sinning?"

The answer to that, of course, is that God gave us free will because He loves us, and because He wants to be loved in return.  Our love for Him wouldn't be real love if it were forced.  We'd be little better than robots, programmed to behave a certain way.

I believe that the tree was planted there because without it, Adam and Eve wouldn't have had the choice to obey or disobey Him, and without choice, there can be no true obedience, or true love, only mindless followers with no will of their own.  

I don't believe He wanted them to eat it at all, but He knew that they would.  He knows all of history; past, present, and future.  We may not understand why He did certain things, but we can be sure that He has His reasons, and that His wisdom is far higher than ours.  (1 Corintians 1:25, 1 Corinthians 2: 16)