It's their instinct to dart back and forth hoping that gives them a chance to escape. They just don't realize that you aren't a predator that is after them.
I had and still have the same issues with squirrels. While my previous bikes all had very quiet free hubs my new bike has a noisy free hub. Squirrel problem still the same.
However if you wouldn't coast, your free hub wouldn't be making noise!