This is talking about two different time periods. In the earlier of the two, the tribes of Ham, Shem, and Japheth all spoke the same language. Later, the people rebelled against Jehovah’s explicit command to spread out and fill the earth. (Gen 9:1) Therefore, God confused their languages, to facilitate his purpose that they fill the earth. Now that they could no longer understand each other, they had no alternative but to spread out and fill the earth. It should be noted that each person did not receive a new language, each family did, which kept the families (tribes) together.