Really good question! I have read that Paul McCartney wasn't sure Yesterday was an original melody and went around for weeks asking people what they thought! So it's not easy, but you can do this. What has worked good for me is to get a catchy melody in my head when i am walking or even working in the yard. No instrument. Clear your head. If you hear a phrase that has a nice bounce, see what you can do with this. Then when you get a good singable line, record it right there. on your telephone or another quick recording tool. Not much worse that loosing a good line!
Hope this helps.