Newton's 1st law of motion states that a moving object will go in a straight line unless an outside force changes this motion. what outside force prevents the planets from moving in a straight line into space?
All objects in space (and everywhere else!) pull each other. This is called gravity. The reason things don't travel in a straight line through space is because everything is pulling each other with gravity.