Most pieces of music will modulate, especially if they are long pieces. It gives the music variety and helps to give it shape: the farther away from the tonic it goes the more tension there is. When the music eventually returns to the original key it feels like a homecoming. 