Pretty much others already have said this: For something that's sold over the counter as a supplement, melatonin can seriously screw with your brain chemistry. My doctor once told me that he wouldn't be surprised if melatonin eventually became a regulated substance. As others have said, the dose matters. I read somewhere once that anything over 1 mg on a nightly basis long-term was suspect, but don't if that's true.
It also gave me the wacky dreams. I don't take it any more -- primarily because I didn't like the side effects, plus it didn't help much with the sleep.
You could try cutting out the melatonin for awhile and see if your depression improves.