I've discovered an interesting songwriting trick revolving around earworms. Often at night I'll have a song stuck in my head all night and every time I wake up it's still there running over and over. Often stretching into the next morning as I take my shower, etc. It's usually the last song I listened to before I went to bed, and it gets particularly bad if I was something I was playing and singing along with.
I keep a playlist of songs to use as inspiration (ok, songs that I want to rip off) but they just kind of sit there and I usually don't remember to actually try to write new songs based on them. Or if I do it doesn't work very well. But a while back, one morning this song came into my head and I recorded it really quickly, then I realized that it was similar in feeling to a song that was on my list of stuff to copy and that it had been the last thing I had listened to the night before.
So now I'm trying to be more conscious about what I listen to before I go to bed. I figure that I can actually absorb the song through the night and learn from it, so I should intentionally pick things I want to learn from rather than accidentally getting something stuck in my brain by chance.