I'm guessing that you're seeing some kind of maggot, the larval stage of some sort of fly. That would indicate that your coffee grounds aren't as dry as you think they are. I've had flies lay eggs in wet grounds, but it makes no difference to me. I just dig those grounds right into the dirt,
maggots and all. That way I don't have to deal with any flies.
I don't dry my coffee grounds out. Whenever a wet soil amendment is dried out, be it manure,
compost, coffee grounds, or whatever, some of its nutrients will gas off, escaping into the air. So in order to retain as much of the nutrients as possible, I immediately add mine to the soil or compost. In regions that get frozen ground, that wouldn't be possible. So drying or ensilaging may be the next best option.