As Catholics, we don’t believe that ANYTHING in the Bible is invented. Rather, everything in the Bible is inspired. In other words, God is the author of the Bible and human authors wrote the Scriptures down under the inspiration of the Holy Spirit.
With that in mind, the Catechism (#115-117) teaches us to recognize that the Bible works on 2 levels: the literal and the spiritual. This means that, even when events described in the Bible may not be intended to be understood literally, they nonetheless teach spiritual truth.
Of course, your question is asking whether or not the infancy narratives (found only in Matthew’s and Luke’s Gospels) are factual (can be taken literally as historical accounts) or figurative. First, we need to recognize that the Gospels as a whole are not intended to be historical biographies but rather, are theological narratives or “portraits” as Fr. Donald Senior describes them (Jesus: A Gospel Portrait). The infancy narratives do not attempt to give us a historical account of Jesus’ birth but rather, they answer the theological question of “who is Jesus of Nazareth?” This does not mean that the infancy narratives do not contain some history in the sense that we understand history today. We do know historically that Jesus was born during the reign of King Herod. On the other hand, we are unable to verify historically that Joseph and Mary migrated to Bethlehem because of a census.
There are many elements of the infancy narratives that we are unable to verify historically. This does not make them unhistorical but rather unverifiable historically speaking, leaving the door open for the possibility that they are based on historical events. The authors wove history and theology together to present us with proclamations of faith rather than with news accounts. Historically speaking, we do not know all of the “facts” surrounding Jesus’ birth. However, the infancy narratives teach us the absolute truth about the identity of Jesus of Nazareth.