In my opinion, the problem is usually that people write riffs and solos with their guitars rather than their minds (I do this too). When you sit down with your guitar to work out a riff, you're actually putting a limit on yourself, letting your fingers walk in patterns that they are used to.
To break out of this cage, it's good to put the guitar aside and try to sing or hum a melody that fits with the song. You will reach a whole new level of musical freedom this way. When you have worked out a nice melody like this, pick up the guitar again and try to play the melody. It may need some modification to work as a riff, but I think it's a good way to write guitar parts. =)
'bane