The word 'infallible' does not mean that the pope is perfect. It also does not mean that the pope knows everything. Instead, infallibility only applies when the pope speaks about solemn, official teachings on faith and morals, and he can’t ever change, add, or subtract Christian doctrine.
He only helps define or explain what we already believe, and he doesn’t do it on his own. The infallible teachings of the Pope are the result of many years – sometimes hundreds of years – of consultation with the other bishops and theologians of the Church. He is, in effect, voicing the belief of the whole Church.