What you mean is not a change of scale, but rather a change of key. A change of key is called a modulation. Modulation is usually established by a full cadence into the new key. If a piece in G major modulates to D major, then you'd expect to see a progression of
D | G | A | D
which would be
I IV V I
in the new key of D major. Sometimes you won't find this entire progression but you will typically find the progression from A to D.
The A chord has a c#, which is not part of the scale of G major, so this is where the listener has the first sense that the tonal center is changing.
Note that in this case G and D are very closely related keys - they have 6 out of 7 scale tones in common, and this is why it is relatively easy to make this change of key.
So you can try and spot modulations by looking for accidentals. So in this case, G major, you want to look for an accidental raising the c to c#. I can see one immediately in measure 20. Also in the following measures, we see c# rather than c. The first occurrence of c natural is measure 24 in the left hand part. Chances are that the key is back to G major at that point. The actual modulation back from D to G will be in that measure or just before or after it.
Now that you found the accidentals, you have to analyze the harmony to figure out what chords are there, and what progression they make. Only after that step you can know for sure at which point exactly the modulation occurs. Of course, you should use your ears too; in many cases the change is clearly audible.
If we take a look at measure 20 (where we first spotted the c#) you can see that the chord is essentially A there. Same goes for the next measure 21. There are plenty of notes in the melody there that are not part of the A chord, but since the bass is A, it still sounds mostly like a chord of A. And in measure 21, the strong beats of the melody are a, c#, e which are in fact chord tones of A. So measure 21 really feels like an A chord.
It is also interesting to look a little further back to measures 17 - 19. As you can see, these three measures avoid the use of c as well as c# - The chords for these measures are G, D, Em. These are all preparation for the A chord introduced in measure 20. The Em chord in measure 19 acts as a so-called secondary dominant, making a transition to A smooth, and then measure 20 "reveals" a change of key is happening by introducing the c# rather than a c natural which one would expect if the tonality was still in G.
In measure 22, 23, 24, 25 the chords are
G D A | D F# A | D D7 | G
So what we see here is that after the introduction of the A chord in measures 20 and 21, we get a brief confirmation of the key of D in measure 23, which is again prepared by the last A chord in measure 22. And again, last chord in measure 23 is A, followed by a D in measure 24. But then measure 24 surrenders back to the original key of G again, by using a c natural. In the chord of D, this c natural is a 7th degree, making this a D7 chord. This is the dominant chord in the key of G. The dominant has a very strong tendency to fall back to the tonic chord, and indeed in this case it returns to G, which is the first chord we find in measure 25. The piece then continues in G.
So all in all, the escape from G to D is really rather brief; probably too brief to call it an actual modulation, it is more a temporary departure than a structural change of key.
In larger pieces, the key change will be explicitly marked by a double line and a key signature. For smaller pieces, the change of key is only temporary and transient, and normally this is not explicitly denoted - they simply write accidentals instead.