I have used analog approaches with voltage control successfully in production (10k/mo) and never had a regulator problem. Simple this 1U high 19"rack was pure analog with an OEM 180W supply that UL dictated a "coke-spill" sealed top, I chose a tiny thermistor epoxied to the SMPS hot-spot to bias a switch to drive the fan ON, above 45deg C. I computed the values and gain in a spreadsheet so the gain was 0 to 100% from 45 to 55'C.
You might find the PWM will work best but alias at some rates with some vendor fans, so test them with a pulse gen. and avoid that PWM rate if using a 2 pin fan.
The problem I had was after a few shipments, fans started to get "stuck" and needed a tiny spin to start up, otherwise they would dither back and forth a couple degrees or simply looked dead. This had nothing to do with analog or PWM control, as I recognized the process design fault as misaligned Hall sensors in the fan. the reason being the max fan power is controlled by sensor magnet alignment and commutation closest to reversal ( before top dead center ) was like a backfire in a piston which made it go back/forth so fast, it stood still. in only 1 or 2 stop positions. So I made a quick fan fail tester with 1 second only 4 seconds off to stop and tested every fan start angle 30 seconds, then after 1 hr found 5 failed in 150 fans. rejected the units. accepted the 145 and sent 1 thousand fans fan to supplier and emailed the Test Design to Distributor& Factory and said if we get 1 more fan failure , they lose our business. That worked. No more stuck fans.
It took me less time to put out this Stop ORder and test 150 fans and send the design procedure than to write up this answer.
Your driver is not linear on V+ high side, and you might want a low side with N type. i.e. the Source to Gnd and Drain to fan(-) and fan(+) to 12V or some other switch. Consider slow startup at 5V for cool and quiet.
Max power dissipation of the fan reduced to 50% at half power and RPM
where the driver dissipates the same power, so clamp with isolation to
a heatsink or frame. In my case it was only a few Watts out of 5W or use PWM if you prefer 3 pin fans and the thermistor speed control bits and pieces cost me ~$2 added cost to cheaper two-pin twin turbo 1.75" fans. 2 much !
Is the distortion on the rising edge? Pull-up of Q1 \$V_{\text{ds}}\$ through R2 is a limiter for bandwidth. At close to \$V_{\text{ds}}\$=0V, BS170 has \$C_{\text{ds}}\$~40pF and \$C_{\text{gd}}\$~20pF. So, time constant for R2(\$C_{\text{ds}}\$+\$C_{\text{gd}}\$) ~ 4usec. After the rise of GPIO has played out, the last 2V to 2.5V of rise will follow that 4usec time constant, which makes the large signal bandwidth less than 100kHz. Other capacitance in the circuit will make things worse. Lowering R2 to 1kOhm would help get the bandwidth close to 800kHz.
Should also point out that \$V_{\text{th}}\$ of the BS170 can be as high as 3V, so there could be units that won't properly turn on. A lower voltage part with lower \$V_{\text{th}}\$ and smaller die size, to reduce part capacitance would be a better choice.
Best Answer
For your first question, yes keep the diode - if it isn't needed because of something special about the fan, it will do no harm. If it is needed then leaving it out will damage the reliability of your circuit. The diode in your MOSFET is not useful to do the same thing.
For the second question, personally, I wouldn't use this MOSFET for this job - it's a 'small signal' MOSFET, and you would almost certainly be much better with a power MOSFET of some kind:
The Rdson is too high - at 0.32A, you'd be dissipating 0.32*0.32*5 = 512mW which is more than the device is rated to dissipate. And that's before you start to think about switching losses caused by your PWM switching.
There are no characteristic graphs for Vgs as low as 3.3V - although you're above the threshold at 3.3V, you're clearly not operating the device in the way the designers intended.
Additionally you should almost always add a resistor in series with the gate of a MOSFET, to control the turn on speed/gate current.
Here's a post about choosing a FET: Selecting a MOSFET for driving load from logic