According to the account in Luke, John the Baptist first encountered Jesus when Panaghia Mary went to visit her cousin Elisabeth. Since Luke relates Jesus’ nativity and infancy narrative in the light of His baptism (John prepares the way for the Lord through his miraculous birth), we do not see John meet Jesus on the occasion of Jesus’ baptism. John’s testimony and mission are presented in the account of Mary’s visitation.
Matthew, on the other hand, first talks of John the Baptist and His first encounter with the Lord on the occasion of Jesus’ baptism. The account in Matthew implies that John the baptist recognises Jesus prior to baptising Him, probably through his prophetic mission and by the work of the Holy Spirit.
John is the only Evangelist to narrate Jesus’ dialogue with His precursor AFTER His baptism. In other words, only in John’s Gospel is John’s testimony presented three times as occurring after Jesus’ baptism and before the baptist’s arrest and imprisonment.
Another significant element in John’s narrative is that Jesus’ precursor directs his disciples to Jesus, who leave the Baptist to follow Jesus. At this point, the evangelist underscores the similarity between John the Baptist and Jesus’ disciples with regard to seeing signs and beleiving in Jesus. Although some of Jesus’ disciples know Jesus and believe in Him on the day they meet Him the first time, they fully and officially acknowledge His power and mission when Jesus performs His first SIGN:
John 2:11
This beginning of miracles did Jesus in Cana of Galilee and manifested his glory. And his disciples believed in him.
More, Jesus’ disciples mostly see His signs, believe Him, and finally give testimony to Jesus. John the Baptist does the same thing: he officially knows Jesus and becomes a witness after seeing a SIGN:
John 1:32-34
And John gave** testimony**, saying: I saw the Spirit coming down, as a dove from heaven; and he remained upon him. And I knew him not: but he who sent me to baptize with water said to me: He upon whom thou shalt see the Spirit descending and remaining upon him, he it is that baptizeth with the Holy Ghost. And I saw: and I gave testimony that this is the Son of God.
John 12:16
These things his disciples did not know at the first: but when Jesus was glorified, then they remembered that these things were written of him and that they had done these things to him.
John 12:41
These things said Isaiah, when he saw his glory, and spoke of him.
John 19:34-35
But one of the soldiers with a spear opened his side: and immediately there came out blood and water. And he that saw it hath given testimony: and his testimony is true.
John 20.8
Then that other disciple also went in, who came first to the sepulchre: and he saw and believed.