Although I have no explicit source to point at to confirm this theory, there is a contextual viewpoint that could offer a possible mechanism that answers the question. Finding sources that would support this definitively would take quite a bit of work but it makes sense in terms of the reasoning.
In general, a large part of the story of the redemption from Egypt involves a particular name of G-d that was revealed to Moshe Rabbeinu. That name is referred to as the '72 letter name' or the 'name of 72 triplets, also called the 'Great Name'.
As explained in Sefer Tzaror HaMor, parshat Beshalach, page 12 starting with the words (ויבאו בני ישראל כו׳) it says that this name is related to the aspect of the redemption that makes G-ds 'Great Name' known to the nations (Mitzrayim). It also explains on page 13 beginning with the words (ובזוהר כתבו כו׳) that this idea is what we say in the the 'P'sukei d'zimra' when reciting the 'Shirat HaYam...' with the words, "וברב גאונך תהרס קמיך כו׳" and that it is also what is mentioned in Yechezkel chapter 38 in relation to the war of Gog and Magog. In regard to Gog and Magog, it says that the 'Komeicha' are like 'buildings' that will be destroyed.
Interestingly, according to the explanation from the Zohar there, which is said in the name of the early Rishon, Rabbi Yosef Kimchi and the Tanna, Rabbi Shimon bar Yochai, it seems to be a direct reference to the attack on the twin towers of the World Trade Center. The destruction of these two special buildings are the sign mentioned in Yechezkel which indicates the beginning of the third and final installment of the War of Gog and Magog.
The words of Yechezkel 38:4, "ונתתי חחים בלחייך כו׳" means 'I will place 'chochim' in 'lechayecha'. 'Chochim' (חחים) which means 'chains', like the reins connected to the bridle of a horse (The bridle and reins are how you control and direct a horse.), and also חוח 'thorns', which if one is pricked by them causes one to move away and to take action.) 'Lechayecha', means (לחיא) 'the cheek piece of the bridle' and also has a meaning of 'your fortresses' (לחייתא means 'fortress'), But when taken literally this can also refer to a pair of 'lechi's'.
A 'Lechi' (לחי) is a pillar attached to the ground and of unlimited height used to create a halachic wall or doorway. When two pillars are attached across the top by a string, they take on this special status of 'lechi'. On August 7, 1974, shortly after the completion of the Twin Towers of the World Trade Center, they were attached by a cable strung across the top of them by Philippe Petit in order to perform his tight-wire walk between the two towers. The twin towers acquired the status of being a pair of 'lechi's'.) This destruction of the two towers serves the same type of purpose as the plagues in Egypt and the splitting of the Yam Suf and heralds the process of 'turning (or converting 'אתהפכה') kol rishei aretz (all the inhabitants of the world) to serve You' like is mentioned in the second paragraph of the Aleinu prayer.
This 'Great Name' is actually comprised of 72 three letter combinations (for a total of 216 letters) which are formed through the weaving together of the three posukim, Shemot 14:19-21. The first posuk is arranged in correct reading order and is associated with Avraham Avinu and the 'Sefirah' of 'Chesed' ('Chesed' or 'Kindness' (חסד) has a 'gematria' of 72). The second posuk is arranged in reverse reading order and is associated with Yitzchok Avinu and the 'Sefirah' of 'Gevurah' ('Gevurah' or 'Strength' or 'Might' (גבורה) is the idea of 'Ish Gever', a person who overpowers their own nature. 'Gevurah' has a gematria of 216). The final posuk is arranged in correct reading order and is associated with Yaacov Avinu and the 'Sefirah' of 'Tiferet' or 'Rachamim'. 'Rachamim' meaning 'Mercy' mediates and balances between 'Chesed' and 'Gevurah' but is inclined to the side of 'Chesed'. This is the process of converting (Called אתהפכה). The 216 letters if 'pronounced' as they are in a single string express as 'Gevurah'. But if 'pronounced' as the 72 triplets, they are converted from 'Gevurah' and expressed as 'Chesed'.
In terms of the Avodah in the first Temple, this process is associated with the moment of the burning of the 'korbonot'. This is described in Midrash as when a 'lion of Heavenly fire' would descend upon the alter and consume the offering, converting it to a 'pleasing odor' (ריח ניחח). 'Lion' (אריה) also has a 'gematria' of 216, an allusion to the aspect of Gevurah being converted by the 'Great Name'.
It is worth noting that in 'Mispar Katan' (ריח ניחח), the phrase associated with the korbonot has a gematria of 33. This is the same Mispar Katan gematria of (חחים בלחייך) from Yechezkel 38:4 if the words and kollel are included.
This type of '72 letter' name is associated with the discipline of Prophecy and there are examples in some of the more obscure kabbalistic literature of other 72 group triplets formed from different posukim.
The concept with this name as used by Moshe Rabbeinu is that meditation upon this name (or, if one is in the state and physical condition where it is permissible to, pronouncing this name) is connected to converting things to their opposite.
It was via use of this name that Moshe smote the Egyptian, converting the Egyptian from being alive to being dead. This name was also connected to the sign given by G-d to Moshe at the burning bush of converting the staff of Moshe into the 'Nachash' and back again. This sign was repeated when first appearing before Pharaoh. It was also associated with the miracle of turning the sea to dry land at the Yam Suf.
This name is also part of the 'kavanot' that are made when saying 'Shema' each day, both on the first posuk and also with the paragraph beginning "V'Hayah..." and again at the paragraph of "Vayomer...".
It is also associated with the 'Avodah of Yom Kippur' when the Kohen Gadol pronounces the 'Great Name' of G-d aloud and the people prostrate themselves before G-d. This was the moment when the crimson string which was tied around the Alter would convert from red to white indicating their 'Teshuvah' had been accepted.
In regard to Bilaam, the Torah states that Bilaam told Balak he could only do what he was permitted to do by G-d (Meaning he could only say whatever curse he was permitted to pronounce.) BaMidbar 22:8-13.
Bilaam essentially knew the precise moment of each day when G-d sits in judgement. (This is why Bilaam's level of prophecy was compared to Moshe's. Just like is emphasized in the Hagaddah in regard to Moshe Rabbeinu when he told Pharaoh the plague of the firstborn would be 'around midnight'. But the commentaries emphasize that Moshe Rabbeinu knew precisely when the plague would begin.) In fact, Bilaam is described in places as the 'Prophet of the Nations', like Moshe Rabbeinu was our Prophet.
But for his curses to be effective, the charge or accusation had to actually exist. Bilaam's curses were only that he drew attention to some deficiency in the accused, meaning the one being cursed, at the moment of judgement which precipitated immediate judgement.
So the fixing of the precise text of his curse had to be revealed to him from Above. This follows the explanation of Kli Yakar on BaMidbar 23:6. That revelation begins with the 'letters of thought' which descend from a level that is called 'Mochah Stimah' and eventually evolves downward to be expressed through the 'letters of speech' which are pronounced with ones mouth. And the conversion from curse to blessing would appear to be at the moment of pronouncing them, when they expressed physically and materially, like is said in Targum Yonatan ben Uziel to this same posuk.
This seems to be the reference being made in B'Midbar 24:1. That the aspect of 'Lo' (ולא---הלך), the 'Gevurah' aspect which expresses through the five parts of the mouth, meaning the five 'Gevurot', went, meaning behaved, like the time with the 'Nachashim', the serpents. The first time was when G-d showed this sign to Moshe Rabbeinu at the burning bush and the second time was in front of Pharaoh. The three 'Brichot' connecting 'Lo' and 'Halach' allude to the three posukim which make up the 'Great Name' of 72 triplets.
This same idea, of 'Gevurah' being converted to 'Chesed', is reflected in what we recall in connection to Tefillin when reciting the paragraph of 'Kadesh...'. That for the Jewish people 'Yad Chazakah' was redemption but for the Egyptians it was the plagues. The hand Tefillin is placed on the left arm, the weak arm and yet for B'nai Yisrael it is 'called' the strong arm, meaning the right arm. The left side is associated with the quality of 'Gevurah' while the right side is associated with 'Chesed'.
The same sentiment is repeated in connection with Purim at the conclusion of Megillat Esther (8:16) which we recall at the conclusion of Shabbat each week. 'For the Jews there was light and gladness and joy and honor." So may it be for us.