MOSFET driver working funny
It's hard to guess what the actual problem in your circuit is, but you can try the following things:


Add a cap close to the uC input of the supplying power, e.g. 10uF 10V
Lower the PWM frequency, 200Hz should be enough to prevent flickering
add resistors between PWM-pin and MOSFET-gate to reduce strong current changes, try 10 to 100 Ohm
Keep the grounds connected! This is important for the functionality.


In your case, I think it's necessary to implement all of these suggestions.