Yep, been there. Something interesting happened not that long ago: I used to have that gasp pretty often, right before dozing off. When I got my really bad panic under control (leaving me with basic, general anxiety), they went away. BUT. This last week I began some pretty intense breathing exercises, which has really been a nice source of relaxation, and I notice that those gasps are back at night. They aren't really a concern of mine now, as I don't feel threatened by it, but it's interesting to note that breathing patterns almost certainly have a strong link to it.
Another thing I suspect is that our brains feel, as we doze off, a sudden sense of relinquishing control of our consciousness, and to an anxious person, that's translated in our breath; a knee-jerk reaction to snatch that control back.
But I'm only speaking from what I've observed. I've no facts to back any of that up. When it really bothered my, I found it was less frequent on my side, and also sometimes reading in bed would make me sleepy, and I'd fall asleep without gasping. I suspected it was from having the mind focused on one thing and not a bunch of other fragmented worries.
Best of luck!