In short
Since the Magi probably started following the star when Jesus was born, it makes sense that Mary and Joseph had found a better place to live in the months it took the wise men to find Jesus.
The reference to the house
seems to indicate that Joseph and Mary did not stay in the place of Jesus’ birth for very long, but managed to find a house. It can be assumed that by the time the wise men arrived, a number of weeks and months had already passed. The wise men had probably first seen the star the moment Jesus was born and only then started their long journey to Jerusalem. It is not clear whether they arrived on the day prior to the Lord’s consecration in the temple (Luke 2:21–38) or the day thereafter.1
11 And going into the house they saw the child with Mary his mother, and they fell down and worshiped him. Then, opening their treasures, they offered him gifts, gold and frankincense and myrrh.