Goat faeces is in small, polished-looking pellets. It would appear that this pellet formation happens inside the goat, because the pellets are expelled en masse rather than in the rapid succession that would happen if the pellets were made by repeatedly opening and closing the sphincter.

How does this happen? And why? Why do goats egest several tiny pellets instead of a big 'log'?

I would put it the other way round! All rodents sheep and goats produce "pellets" and horses are again discrete lumps. In contrast cows produce pats and humans logs. I presume the differences are due to the amount of musculature and tone in the large bowel which does or does not break the faeces up into the shapes above. Why the differences exist I don't know - I presume it is in part differences in diet but what the evolutionary advantages might be of each way of defecation are not immediately obvious to me.

As an aside I hope you are impressed I manage to type the above without using any scatological humour or puns!