The Gospel of Luke says that Mary and Joseph lived in Nazareth at the the time of the annunication (Lk. 1:26) and during part of Mary's pregnancy with Jesus (Lk. 2:4); it also says they returned there later after Jesus was born (Lk. 2:39). However, in the Gospel of Matthew there is a line which seems to imply that Joseph and Mary were not living in Nazareth until after Jesus was born and they returned from Egypt:
"And [Joseph] arose, and took the young child and his mother, and came into the land of Israel. But when he heard that Archelaus did reign in Judea in the room of his father Herod, he was afraid to go thither, notwithstanding, being warned of God in a dream, he turned aside into the parts of Galilee, and he came and dwelt in a city called Nazareth" (Matt. 2:21-23 KJV).
"So he got up, took the child and his mother and went to the land of Israel. But when he heard that Archelaus was reigning in Judea in place of his father Herod, he was afraid to go there. Having been warned in a dream, he withdrew to the district of Galilee, and he went and lived in a town called Nazareth." (Matt. 2:21-23 NIV)
If they had been living in Nazareth before, then why mention them not going to where Herod's son was because they were afraid? Is the Gospel just saying that they would have went to where Herod's son was ruling rather than back to Nazareth, had they been able, but since they feared for their lives settled for the second option of returning to Nazareth? Or is there some other answer that I'm not seeing?