So to sum up, why should I play different notes in that way, and how would I know to play in that way, or is there no way of telling.
That's an excellent question with more than one answer.
The guitar is different from say a piano in that there are usually several different strings where you can play the exact same note at the exact same pitch. There are many reasons a composer or guitarist will choose certain positions for a particular note in a piece.
First let's throw out the obvious fact that if the music calls for a note in a different octave (E3 vs E4 for example) it will be necessary to play the note on a fatter or thinner string or higher up the neck to get the higher or lower pitched version of the given note.
So let's look at different reasons to choose different places to play the exact same note at the same pitch.
In the piece you sited as an example, one of the primary reasons I see for the choice of where to play the various identical notes is because of the picking pattern. When playing classical guitar you will most likely be finger picking with a certain picking pattern or patterns. The more rhythmic and easier to maintain finger picking patterns involve alternating between bass notes picked with the thumb and treble notes picked with fingers. It's just a very natural movement. In your example it might not be bass notes but there is an obvious intent to establish a thumb finger alternating picking pattern.
It's much easier to play rapid repetitions of the same note with an alternating thumb finger pattern than it is by repeatedly picking the same string. Also, the thumb-finger picking pattern is used throughout the piece and helps establish a rhythm.
Other reasons to choose to play a given pitched noted at one place verses another would include the tone you are looking for and what you want the note to do after you play it. For example play your open high e string. Then play that same note on the 9th fret of the 3rd string. You will notice that it has a different timbre - a different quality. Maybe a little fuller and less tinny. So the sound you want could influence where you choose to play a note.
But also consider that if you wanted the note to sustain (continue to ring out) after you played it while you play other notes, it might be easier to do that with an open string. To allow a note to sustain on a fretted string requires you to keep your fretting finger locked in place and limits where else you can play. Of course there are only 6 notes that can be played open on a 6 string guitar but there may be instances where one of those notes is intended to continue to ring while other notes are played. Alternatively if you intend to mute a particular note after or while it is played, it might be easier to play a fretted version of that note (even though it may be one of the open string notes), particularly if palm muting would tend to mute other strings that you did not want to mute.
Another consideration is where are you going next with your melody or harmony. Certain positions of playing a series of notes may put your fingers in a better position to play a particular chord that comes up in the piece. Or certain melodies might be mixed in with a series of chords intended to be played with a specific voicing. So the location of where you play a given series of melody notes could impact how easy it is to move back and forth from the individual notes to the indicated chord shapes.
Finally - sometimes where to play a note is nothing more than individual choice. In classical music with finger picking patterns and alternating bass lines or even counterpoint being played alternately between thumb and fingers, the choice of where to play a given series of notes is less flexible (from a practical point of view). But if you are playing a lead run, or some melodic fills with a pick, there may be several places on the fretboard where the desired note run can be executed and often it boils down to what feels right to the guitarist.
In a case of a lead solo that is not part of a classical repertoire, many guitarist will use the tab to find the basic notes but then may choose personally to play those same notes in a different position on the neck.
There are probably some other reasons to choose a particular position to play a particular note that I have not though of (muting adjacent strings perhaps being one?). But I think you can see that there is often (not always) a valid reason to choose one versus another. As you gain experience you will find your own reasons.
In the meantime, particularly with music written for classical guitar, your best bet is to start with the suggested positions and finger picking patterns. If after you get a feel for what the composer intended the piece to sound like - you find an easier way to play it, feel free to experiment.
Have fun learning!