John the Baptist NEVER doubted that Jesus was indeed the Messiah. The verses you are quoting refer to John helping his OWN disciples come to the fullness of FAith in Jesus. His way of doing it is as you see in those verses. IOW, he tells them, go ask Him yourself if He is the One. Jesus replies to them AS IF it were a question from the Baptist, BUT AGAIN, he is telling them these things for THEIR OWN benefit, not John the Baptists.
John the Baptist was THE PROPHET, whose duty was to point out Jesus as the expected One, and the Messiah. That is why we see several different ways in the Bible whereby he Pointed Out Jesus for everyone, and just his own disciples as well.
Clear your mind of any doubts. John the Baptist KNEW when he saw the Holy Spirit in the form of a dove come and rest on Jesus. John the Baptist was already fairly certain BEFORE he baptized Jesus, which is why he protested that it was Jesus who should be baptizing him!