Why is some scat in the form of little pellets?
According to this article:

The material that cannot be broken down any further, such as
indigestible fiber, passes directly into the large intestine.  Here
water is reabsorbed and the material is passed, making up the round
droppings you see in your rabbit’s cage.  This indigestible fiber is
important in the diet of the rabbit as it helps to stimulate
intestinal contractions, which keeps the chyme moving through the
gastrointestinal tract.

While this article is specifically about rabbits, all herbivores require high quantities of fiber in their diets. Ruminants such as deer have different stomachs, but it is the large intestine, which is commonplace, that these pellets are formed. Fiber tends to clump together (either because the strands are attached or intertwined), and contractions in the intestine as the material is dehydrated cause these clumps to roll around similarly to pebbles in a rock tumbler, causing them to form round pellets.
Carnivores and omnivores have (and need) less fiber in their diets, so this phenomenon is not present in their feces.