Why is sloshing undesirable? How is sloshing prevented by installing baffles? Are there any other methods to prevent sloshing?
Why is sloshing undesirable
Because it can cause fuel flow interruptions, this would be bad for fuel injection systems. If the fuel sloshes to one side of the tank, the fuel pump would get a gulp of air instead of fuel, causing the vehicle to stall at some point. Also sloshing caused fuel gauges to wander back and forth, Ford introduced a slosh module (basically an electrical buffer for the fuel gauge) many tears a go to prevent a wandering fuel gauge.
How is sloshing prevented by installing baffles?
Same reason walls slow down or stop wind
Are there any other methods to prevent sloshing?
Yes, some race car fuel tanks have open cell foam in the tank, this works really well to prevent sloshing.
While the other answer is good, there is one other reason that sloshing of fuel is limited, and that is weight transfer.
Having a large mass of fuel move to one side of the centre line while cornering can upset the driver's expected balance of the car, and this is more noticeable with a motorcycle. Same as if the rider's backpack shifts position.