Hi,
[...] why (for the PWM to work correctly) do i have to connect the two grounds together.
Two answers, take your pick...
1) Because the electrons need a return path - you cannot communicate on a single line, as there is no reference telling the other side whether the line is high or low.
If you just connected one pole of a battery to a circuit, would you expect it to work then?
2) You don't, just get an opto coupler and communicate via light (the opto coupler needs to have two connections to each circuit though.