Francis Bellamy wrote the pledge in the early 20th century. He, like his more famous cousin Edward Bellamy, was a utopian socialist who understood that “nationalism” and “democracy” were more palatable terms than socialism, and he believed that if you could indoctrinate children to recite a pledge at an early age, they would be fully incorporated into the nationalist agenda by the time they were adults.
He had two goals in mind: 1) as you say to erase the idea that the United States could be divided and to drive a nationalist agenda and 2) to make Americans believe that “liberty and justice for all” was one of the core principles of the United States; he stole that from the goals of the French, not American, Revolution: “liberty, equality, fraternity.” Most also don’t realize that when children first recited the pledge they gave a salute similar to that of the Nazi salute. It was only changed during WWII after FDR and other Americans figured out that it smacked of fascism (still does) so you now put your hand over your heart.
Hope that helps.