It goes to the formation of the solar system(as we explained in the previous question).The solar system formed out of a clump of gas and dust.Then gravity collapsed this clump of gas and dust in the direction of its axis(that takes less energy).Thus the cloud become a spinning disk,then planets formed out and kept located in the same plane till today.And due to the conservation of angular momentum they keep orbiting in the same plane.
The Earth has its own magnetic field , it acts like there is huge bar magnet buried inside,but this bar magnet is not on the earth rotational axis it is shifted by some angle.The south of the bar magnet is on the magnetic north and the south polarity is on the magnetic north(image).As opposite polarities attract the magnetic needle (north) is attracted to the south polarity in the magnetic north.That’s why the needle always points north.If you want to know “why earth has magnetic field?”go to letter E.