According to a 2013 paper published in Frontiers in Zoology, it may be that dogs attempt to align themselves with Earth's magnetic field before pooping.
Specifically, they seem prefer to defecate along the North-South axis if the magnetic field is stable.