You're correct. The idea of 24...a6 is to allow the king to avoid a perpetual. This could be of relevance if Black's queen moves away to go after White's king (e.g., ...Qc5). It could also be useful for the king to hide on a7 if things go haywire and a dangerous attack happens, such as the h-pawn promoting or White's rook getting involved. Although, in the position before 24...a6, Stockfish gives an evaluation of 0.00 no matter whose move it is. So purely in an objective sense, ...a6 isn't a necessary move -- but practically it's quite nice. Your anticipated move of 24...Qh4 is also evaluated at 0.00 by Stockfish, so it's just as good.
One interesting line goes 24...a6 25.h6 (White has other moves that are fine too) 25...Qc5. Now White's going to get mated from ...Qf2 if he's not careful. For example, 26.Qe8 Qf2 27.Qe7+ Kb8 28.Qf8+ Ka7. Now White can't stop the dual threats of ...Qxb2# and ...Qc2+ (picking up the d1-rook with mate). Another faulty try is 26.Qg7. The idea is that 26...Rxg7 27.hxg7 sees White about to promote, leaving him up a rook. However, Black has 26...Qf2, and 27.Qxf7+ Kb6 28.Qxe6+ Ka7 sees Black's king being safe, again thanks to the a6-pawn. Therefore, White's only 26th move which maintains equality is 26.Ka1!, preparing to defend with Rb1 if needed.
25. h6
in your expected variation is impossible. Do you mean25. h3
?