Hmm. Thought provoking. I'm not a musician - I'm a retired computer programmer/analyst - but as far back as middle school (called "jr. high school" back then) I was trying to scribble down musical ideas that came to me. Fast-forward 50-some years, I retired from IT, discovered notation software, and then had assistance in my scribbling. After another year or two (with the prompting / insistence of members of this forum) I found a teacher / tutor to help instill some music theory, and have been working with him for the past 10 years or so.
At one level, I compose because I get musical ideas and want to do something with them. That's for composing in general. That drive has been with me all my life. But it's not limited to music. It had a parallel in my IT career, too. Regardless of what official work I was given, I would see something that needed to be done and would work on it (usually) in my spare time until I had a solution to whatever was bugging me. I seem to have a creative urge.
At another level, my teacher asks "What do you want to do next?" or suggests "Maybe it's time to try a fugue again". That's for composing a specific piece. But it my creative urge doesn't necessarily obey orders well. Given "write a fugue", out comes "Little Suite for Wind Quintet". So a piece gets written because I'm wasting my teacher's time if I'm not working on something. A specific piece gets written because it wants to be written (or so it seems to me).