As a transition from your work day to your writing session.
If you find that you're having trouble shaking the concerns that you dealt with during your job time (or family time), listening to a music track can help you make the shift.
Experiment with what works best for you. For some people an upbeat tune is most effective, others prefer a meditative track that helps them to calm down and re-focus.
To energize you when you feel too tired to write.
A recent study looking at the use of music to empower athletes tested 31 clips and found the two that were most effective were "We Will Rock You" (Queen) and "Get Ready for This" (2 Unlimited), but you probably already have tracks that you know pump up your energy levels.
To evoke the mood that you want to create in what you are writing.
If you're writing a horror script or novel, it could help you to listen to a soundtrack from an existing horror film, for instance. (Some people find it too distracting to have music playing while writing, this is something you'll have to try and see whether it works for you.)
To tune in to the energy of your major characters.
What song or music track would best represent your protagonist's energy or world view? How about your antagonist? Listening to these before you write a major scene can be useful.
If you have any other ways you use music to enhance your writing or creativity, feel free to share them in the comments section!