Arduino PWM vs. Potentiometer
If the ends of the pot are not 0-5V, then there's no telling what will happen. Did you measure the voltage at both ends of the pot in a running system?

I assume you're filtering the PWM output with a RC filter?

PWM is a voltage source.  The potentiometer is a passive variable resistor.  It's hard to tell how the rest of the system is reading the pot.

Your 0-5V PWM would only work the ends are 0-5V, you remove the pot, you connect your RC filtered PWM output to the slider pin, and the measurement circuit doesn't try to draw more current than the PWM output can provide (as reemrevnivek points out).