It is important to note that infallibility does not mean that the Pope is without sin, merely that certain pronouncements made on matters of faith and morals are supposed to be protected from error by the Holy Spirit. This protection applies not just to the Pope, but to the congregation of Bishops as a whole.

As well as being rarely invoked, this doctrine is actually relatively new, having been defined by the First Vatican Council in 1870. Catholic theologians, however, will hold that the doctrine has always been true, it was just never expressed in these terms before the nineteenth century. The scriptural precedent normally invoked for the doctrine is Christ's words to Peter:

Thou art Peter and upon this rock I will build my Church; to you I give the keys to the Kingdom of Heaven. Whatever you bind on earth is bound in heaven; whatever you loose on earth is loosed in heaven
The Church also draw on their history, and their own form of logic, to back up the doctrine.

The logical argument for infallibility runs along the lines that as Christ gave Peter and his successors the authority to bind and loose, it would be a terrible thing altogether if Peter's successors were able to bind the faithful to error. Christ, however, would surely never allow this, so it follows that solemn pronouncements of this kind must be protected from error.

But the Catholic Church, you cry, has a long history of errors of the most grevious nature, false Popes, schisms and all the rest of it. This may be true, but the doctrine of infallibility applies only in very limited circumstances, viz.

When the Pope intends to teach by virtue of his supreme authority on a matter of faith and morals to the whole Church, he is preserved by the Holy Spirit from error. His teaching act is therefore called "infallible" and the teaching which he articulates is termed "irreformable"
So far, the church has been careful not to term "irreformable" any doctrine which may be subject to change in the future, or which sets it at odds with its own believers, such as the idea that contraception is sinful, priests cannot marry etc. etc.

In conclusion, papal infallibility does exist, and in a sense is quite a scary doctrine, in that in theory it would be possible for some future pope to declare it an article of faith that it is lawful to kill Muslims or some such outrage. In such a case, however, I imagine it would not be beyond the church's powers of casuistry to retrospectively find a reason why this pronouncement was not, after all, protected by infallibility and thus true for all time. The important thing to remember, however, is that the Pope's periodic pronouncements on public morality, e.g. the sinfulness of homosexuality, the unlawfulness of woman priests etc., are not necessarily covered by infallibility. This is not to say that the Pope doesn't mean them, just that he has yet to declare ex cathedra that they are irreformable matters of faith.