The primary benefit of using a coffee grinder as opposed to buying pre-ground coffee is that the coffee is fresher and tastes more flavorful. The flavor of coffee comes from inside the bean, so keeping it intact until just before brewing makes for better coffee.
There are many reasons the coffee bean loses flavor if pre-ground. The first is contamination. Contamination occurs in pre-ground coffee because once coffee is ground, the oils in the beans absorb other flavors and aromas; keeping the coffee bean intact longer avoids this. Oxygen can even contaminate coffee; the flavor and the aroma of coffee diminishes if exposed to too much oxygen. The oils of coffee can also be diluted if pre-ground by any moisture in the air, as coffee is water-soluble. Carbon dioxide is created when coffee is roasted, and liberating this gas prior to brewing, as happens with pre-ground coffee, causes the coffee to lose a substantial amount of flavor.
Using a coffee grinder also allows for greater control over how the beans are brewed at home. Pre-ground coffee already comes ready for a specific type of brewing. Buying whole beans and using a coffee grinder allows beans to be ground coarsely for French press in one sitting, and medium for a drip coffee machine the next.