It happens. A lot of Friendly fire takes place by infantry which is why you do a few things-
1. Until your 2nd line of troops is going to go into combat, keep fire at will off. Have all lines behinf the front line with no fire at will. When you want them to engage, make sure none of your troops are in front of them within range.
2. Make sure you don't hit by crossifre. For example, never surround an enemy unit and fire on all sides, the bullets that miss will pass the enemy formation and hit one of your troops on the surrounding side. This butchered the confederates at Shiloh.
3. Properly align your lines so they do not overlap. If handling more than 1 unit, never actually click the 'fire' button on another enemy unit. otherwise the computer will form the men for you, and you might have friendly fire. Instead, aling your units so there's no overlap, and then click 'fire at will'.
4. Never line up your squares. If you are forming numerous square formations (Like in a Waterloo situation) form your squares in a checkerboard fashion for two reason-
A. This stops friendly fire. Otherwise, if cavalry is going between two squares, and both sides of the square facing that unit fire, where do you think the stray bullets go? Your men in the other square.
B. This makes it even trickier for the cavalry to beat, because they have to weave in and out between squares, instead of simply having to go past a line of squares.
So yes, friendly fire is rampant, but if handled properly, can easily be avoided.