The Story in the Bible
Now when they had departed, look, an angel of the Lord appeared to Joseph in a dream, saying, "Arise and take the young child and his mother, and flee into Egypt, and stay there until I tell you, for Herod will seek the young child to destroy him."
And he arose and took the young child and his mother by night, and departed into Egypt, and was there until the death of Herod; that it might be fulfilled which was spoken by the Lord through the prophet, saying, "Out of Egypt I called my son."
Then Herod, when he saw that he was mocked by the Magi, was exceedingly angry, and sent out, and killed all the male children who were in Bethlehem and in all the surrounding countryside, from two years old and under, according to the exact time which he had learned from the Magi. Then that which was spoken by Jeremiah the prophet was fulfilled, saying,
"A voice was heard in Ramah, lamentation and weeping and great mourning, Rachel weeping for her children; and she would not be comforted, because they are no more."
The History behind Joseph, Mary and Jesus Escaping to Egypt in the Christmas Story
Although Herod was the 'King of the Jews', he wasn't actually a Jew! He was a Nabatean and was really a 'puppet king' for the Romans. Herod was hated by most Jews and he didn't like them either! So when the Magi said there was a new 'King of the Jews' - who was actually Jewish - Herod was very angry and scared that the new King could come and take his power away.
Because Herod was unable to find out where Jesus was from the wise men, he thought the only way of making sure Jesus was killed, was to kill every baby boy under two years old in Bethlehem and the surrounding area. Probably only about 20 babies would have been killed, but even that fact is really horrible. So his cruelty would had brought terror and grief to many homes. But Jesus was kept safe as Joseph took him and Mary to Egypt just in time. This was not the first time that Herod had killed people to keep them quiet - he even had killed people in his own family in the past!
The killing of the boys is mentioned in a Roman book in the 5th century, called "The Saturnalia of Macrobius" where it also claims that even one of Herod's son's was killed. It quotes the Roman Emperor Augustus as saying: "It is better to be Herod's pig than a son." It's also described in "The Infancy Gospel of James", although later scholars have cast doubt over both of these works.
However, the very respected Roman historian Josephus records many terrible acts in the life of Herod including the execution of his wife, son and brother-in-law! Josephus also records Herod's death as taking place in 4 BCE/BC, so Jesus being born about 5-7 BCE/BC makes even more sense.
Jesus becoming a refugee and going to Egypt fulfilled some very old prophecies in the Old Testament of the Bible. The family probably didn't have to spend too long in Egypt as Herod died soon after this.
The gifts of Gold, Frankincense and Myrrh, which were brought by the wise men to Jesus, when he and his family were living in Bethlehem, could well have been used as 'currency' during the families' escape and life in Egypt.
Frankincense and Myrrh are resins which come from trees. They have medicinal uses and were (and still are) used in many religions. They were also (and still are!) very valuable; at the time of Jesus they were worth MUCH more than the gold!