Writing when it comes to you or when you are inspired I think is the best way to write. And you can hear it, even from pros. You see it with artists too.
But to make a living, you have to be able to produce and write while perhaps being uninspired. For this I learned from an artist to work on something totally out of your element. I do mostly metal, but working on a jazz tune, or pop song, or avant-garde or techno even can really be fun and super inspiring in general. The artist I know normally worked on southwest impressionistic landscapes...but he would do victorian paintings, trains, photography, something way different.
Along those lines, he would do renditions of paintings as well. In music I wouldn't say learn a cover, but maybe work on a song in the realm or of the same vibe or structure but put your own unrecognizable spin on it. It is especially good practice when writing for others, when you get the whole, "we want something like Ted Nugent meets Lady Gaga but more country" you have a better chance of getting there.