How do I eliminate PWM noise when driving a fan?
Driving a fan by switching the supply is firstly risky. BLDC fans have electronics in them and your switching these on and off at high speed. Not how they were designed. You risk killing the electronics like this over time.

Adding the cap helps because you are removing nasty power spikes into the fan. Adding the inductor is a good idea and if you look at what people are suggesting you will see that the best way to speed control a BLDC fan is with a constant current buck regulator.

This way you PWM the FET that is feeding energy into the inductor (energy store) and place a fly back diode to circulate the power when the FET is off. This will keep a steady flow of power in the fan, minimal noise and not risk killing the fan long term.