Melkor existed because without him, nothing would be appreciated. If then was only perfection, what would anyone strive for? If there were no such thing as temptation, where could we improve ourselves? Remember Eru's examples to Ulmo - without Melkor's bitter cold and unbearable heat, water would be water. No ice, no frost, no steam, no vapor nor clouds. In his attempts to ruin things, Melkor succeeded only in changing them to things just as beautiful, yet unconsidered by the other Aunir. Melkor was there to illustrate to the Ainur that they did not see, know, nor comprehend everything. Nor did Melkor comprehend that his efforts would only play back into the hands of Eru. Yes, he forged tragedies as well as new concepts, but learning has its costs, as Eru knows well.
As far as elves and men are concerned, their situation is very comparable to our in regular earth. We have trials daily, always based on some weakness borne by either ourselves or those around us, usually both. In Middle-Earth, the basis for the weaknesses of elves and men were things like temptation, sloth, greed, lust for power, etc., all things that can be traced back to the evil embodied in Melkor and Sauron. The elves became a better, if sadder, race because of Melkor and Sauron. Their lore became richer, their wills became stronger, their creations more enduring. Men, or some of them at least, learned and forgot, re-learned and forgot again... such is the weakness of the aftercomers, but also a symptom of their shorter life span.