The Bible records the events of Balaam's life in Numbers 22-24. He appears to play a small role in Scripture, but he is used as an example in four other OT books and three in the NT.
Balaam acknowledges the God who identified Himself to Moses in the burning bush. Balaam seeks an answer from the LORD, and the LORD answers him. If the events in chapter 22 were all we knew of God and Balaam, we might think God was capricious or fickle, since God told him to go with Balak's men but was angry enough to kill him when he did. But God knows the hearts of men, and He knew Balaam wanted the wealth Balak offered no matter what he said.
Aren't you amazed at what lengths God goes to get someone's attention? He will even use a talking donkey! When He got Balaam's attention, He opened his eyes to see what was going on. Remember when Elisha prayed for God to open his servant's eyes in 2 Kings 6:16-17? Like Balaam, he, too, saw God's kingdom reality. There have been times in my life I sure would have liked to have those eyes.
Balaam is a great warning to me. When I first started reading about Balaam, I thought, "He has seen the error of his ways—he is the real deal!" But, I later realized that was not the case. In 2 Peter 2:15-19, Jude 11, and Revelation 2:14, Balaam is used as a prime example of a false prophet. Peter calls these false prophets waterless springs who promise freedom but are themselves slaves to depravity. Jude refers to false prophets as "shepherds feeding themselves, waterless clouds, fruitless trees, wild waves and wandering stars."
I have to be careful and examine everything just like the Berean's in Acts 17:11. "They received the word with all eagerness, examining the Scriptures daily to see if these things were so." They searched the scripture to make sure what the Apostle Paul said was true. I must be cautious about what I accept as truth because even false prophets will speak some truth. The prophecies of Balaam in Numbers 23 and 24 are an excellent example of a false prophet speaking truthfully. However, in Numbers 31:16 we learn Balaam leads Israel into apostasy.
LORD God, thank You for the Truth. Your Word is truth. I know it is through Your truth that I am sanctified. Holy Spirit, I want to distinguish the truth from everything else. I know false teachers can weave the truth and the lie together very well. Please teach me to be both a discerning and discriminating listener.
As you know, many titles of the Psalm's provide the circumstances from which each is written. It is always worth your effort to read what happened in David's life that led to a particular prayer. This Psalm was written from the events in 2 Samuel 15:13-16:14. I suggest you read that passage then reread the Psalm. You will find a depth of meaning in the prayer that a cursory reading often misses.