That's a very good question, and one that I wondered about for a long time.
To understand why John asked such a question, you have to understand that he was in prison and had only stories about the man he sent his disciples to go and see. He had no way of knowing if it was the same man that he had baptized. And since there were a few impostors at that time claiming to be the Messiah, John sent his disciples to ask him a direct question, knowing that the Messiah — including the person he baptized — would give an answer that only the Messiah would give. And keep in mind that we do not have the actual word for word question that they asked. But it's not hard to imagine that John asked his disciples to go and see if the man he'd been hearing so much about was the same man that he'd baptized in the Jordan river.
Also keep in mind that because John knew he wouldn't be alive much longer, he wanted to make sure that he wouldn't be sending his disciples to follow a false Messiah. So he wanted to ensure this was the person that he had baptized.
Most Christians, unfortunately, do not recognize the significance of Christ's answer, or what passage he quotes in order that John would know without question that he is the Messiah. For Jesus actually quotes a passage from the Dead Sea Scrolls as his answer to John.
So lets compare what the passage in Matthew tells us and what the scrolls say.
Matt 11:4-6, 12 (NLT):
Jesus told them, “Go back to John and tell him what you have heard and seen – the blind see, the lame walk, the lepers are cured, the deaf hear, the dead are raised to life, and the Good News is being preached to the poor. And tell him, God blesses those who do not turn away because of me …
(12) And from the time John the Baptist began preaching until now, the Kingdom of Heaven has been forcefully advancing, and violent people are attacking it.
Many Christians, including the majority of bible scholars, believe Jesus was referencing a prophecy from Isa 35:5, 6 when he gave this message to John’s disciples. But Isaiah only mentions; the blind seeing, the deaf hearing, those who cannot speak singing, and the lame leaping. There is no mention of the dead being raised, the good news being taught, or the heavens advancing.
Now compare Christ's answer to the Redemption and Resurrection scroll that is part of the DSS.
Frags. 2 + 4 Col. 2:1, 2, 7-9, 11,12:
For the heavens and the earth shall listen to His Messiah and all which is in them shall not turn away from the commandments of the holy ones …
7 For He will honor the pious upon the throne of His eternal kingdom, setting prisoners free, opening the eyes of the blind, raising up those who are bowed down. And forever I shall hold fast to those who hope and in His faithfulness shall …
11 and the Lord shall do glorious things which have not been done, just as He said. For he shall heal the critically wounded, He shall revive the dead, He shall send good news to the afflicted, He shall satisfy the poor, He shall guide the uprooted.
Frags. 7 + 5 Col. 2: 5, 6, 8, 14:
They shall be destined to die, when the Reviver raises the dead of his people …
8 And He shall open the graves …
14 and the heavens shall advance.
It is pretty clear that Jesus is referencing a passage from the DSS that specifically relate to prophecies about the Messiah. But they are passages that the Pharisees and Sadducees would not be aware of as they are not part of the OT canon. It was prophecy, however, that John and his disciples were very familiar with.