The Bible doesn't itself have anything to say on the subject of Mary's conception (or birth), so the idea must have come from an outside tradition. I argued in a related question that Mary's honor needed to be defended at a very early stage in the Church's history. But the Immaculate Conception doctrine came much later.
However, the doctrine seems to logically follow from the related doctrine that Mary was without sin when Jesus was born. Augustine expressed this doctrine in his On Nature and Grace:
We must except the holy Virgin Mary, concerning whom I wish to raise no question when it touches the subject of sins, out of honour to the Lord; for from Him we know what abundance of grace for overcoming sin in every particular was conferred upon her who had the merit to conceive and bear Him who undoubtedly had no sin.
In context, Augustine examined a list of pious men and women that Pelagius asserted had lived their entire lives without sin. Augustine excluded "the mother of our Lord and Saviour" and posed a hypothetical question: Would the rest of the people on the list agree that they were without sin or would they agree with 1st John 1:8 (ESV):
If we say we have no sin, we deceive ourselves, and the truth is not in us.
But Augustine didn't actually assert that Mary was without sin. Rather he suggested that she was granted the grace to overcome sin on the basis of 1st John 3:5 (ESV):
You know that he appeared in order to take away sins, and in him there is no sin.
Notice that the main reason for considering the idea that Mary lived a sinless life is the same apologetic reason for considering the idea that Mary was a perpetual virgin: out of honor toward Christ.
Interestingly, Augustine in this work fought the heresy of Pelagianism and asserted the doctrine of Total Depravity. Therefore, he ought to have had every incentive to pin original sin on Mary at this point if he could bring himself to do so. That he didn't strongly suggests that he at least considered the idea that Mary was sinless from birth. However, his reasoning would have derived from the nature of Jesus and not the nature of Mary herself.
Aquinas stops just short of asserting that Mary was born completely sinless:
And although this appears to be part of the dignity of the Virgin Mother, yet it is somewhat derogatory to the dignity of Christ, without whose power no one had been freed from the first sentence of condemnation. And though, through faith in Christ, some were freed from that condemnation, according to the spirit, before Christ's Incarnation, yet it does not seem fitting that any one should be freed from that condemnation, according to the flesh, except after His Incarnation, for it was then that immunity from condemnation was first to appear.
(Note that Aquinas uses the word "fomes" as shorthand for the inclination to sin. He presumes that Mary was freed from that inclination from her conception until Jesus' conception so that He would be born without the taint of sin.)