
Studio time can be quite expensive (it's not rare for the services of a reasonably high quality studio to run at $100 per hour or more) X Research source, so every time you make a mistake and need to start over, you're losing money. While you can easily get away with making a few mistakes when you're recording in your garage, showing up to a recording studio unprepared can be embarrassing and costly. This is especially important if you're using a professional recording studio.
If you can't, you risk wasting lots of time playing your song over and over as you try for a perfect take. By the time you turn on the mics, you'll want to be able to reliably play through the entire song without making anything rather than insignificant, tiny errors. No matter when and where you're recording, it's always in your best interest to practice your song until you know it like the back of your (hopefully callused) hands.
For more information, see How to Write a Song. In some genres of music, like Jazz, entire sections of the song can be improvised - still, even in these cases, the musicians know when to begin and end each part of the song and how to stay in time with one another. Some artists, for instance, record their solos live in the studio. This means that your song's structure needs to be more or less decided-upon when you arrive at the studio, but it doesn't necessarily mean that you need to have every note pre-planned. This saves you the time of having to re-record numerous takes as you figure out your song and, if you're using a professional studio, the money needed to pay for studio time. Whether you're recording in your garage or at Abbey Road studios, you'll want to have your entire song figured out before you start to record. Trying to record a song you haven't finished writing yet is like trying write a novel without any ideas about the plot or characters you're going to use - very tricky.