If I move a window quickly to the right or left I often find myself in a different space. Is there a way to prevent this
You must hover with the mouse at the edge of the space for a certain, very brief, period of time before the space switches. To avoid this, you can increase the timed delay such that you never inadvertently trigger the behavior:

defaults write com.apple.dock workspaces-edge-delay -float 9;
killall Dock;