Humans were hunger-gatherers for the longest time - what happened to make them settle down and create civilizations like Babylon or Egypt? Did a specific thing force them to do so, or was it a gradual thing, where people started to discover agriculture and so settled down?
It's all about agriculture. As people grew in number, they had to cover more and more land hunting and gathering to support themselves. Eventually, they learned how to grow and harvest wild grains and other plants to eat. They were able to learn to do so well enough that they actually had a food surplus. However, in order to grow crops, you have to remain in one area. This led to the creation of permanent settlements, later cities.
Even in the ancient world, news traveled fast. There was still trade, even amonst nomadic peoples, and the technology of agriculture would have spread like wildfire.
As far as why the specific locations, the Nile River flooded regularly, coating the floodplains with nutrient-rich silt that was ideal for growing crops, and made Egypt one of the largest economic powerhouses of the ancient world. Likewise, Babylon, Assyria, and other ancient empires were also located in the Fertile Crescent in Mesopotamia, which let them excel at growing crops; essentially, the more crops you can grow, the greater your population can grow, and also the fewer people you need to be devoted to growing food, while the rest can work on other things, like military service, religion, art, working a trade, or technological advancement.