Jesus said, “I am the Light of the world; the one who follows Me will not walk in the darkness, but will have the Light of life” (Jn 8:12). The objection that the Pharisees raised was in response to these words. They argued that since Jesus said these things about himself, his testimony could not be true. It was a legal argument and reflects a mindset wherein they were already putting Jesus on trial.
In John 5:18-31 there is a similar incident where Jesus’ opponents objected to something that he said about himself. When he was questioned for healing a sick man on a Sabbath, Jesus said, “My Father is working until now, and I Myself am working.” (Jn 5:2-17).
For this reason therefore the Jews were seeking all the more to kill
Him, because He not only was breaking the Sabbath, but also was
calling God His own Father, making Himself equal with God. – Jn 5:18
The Pulpit commentary depicts the unspoken disapproval and objections that underlie the debate between Jesus and his opponents:
Verse 31 [Jn 5:31]. - We can hear between the lines the cries of an excited
crowd, declaring that these words are simply his own. Such testimony
as this to himself must be sustained and sanctioned. Why and how can
this Teacher take such ground as to assert about himself what no
prophet, no rabbi, no chief priest of the people, not even the
greatest man of men, Moses himself, had ever dared to claim?
In the discourse in John 5, Jesus responded to their objections by laying out the testimony that the Father gives about him through the testimony of John the Baptist, of Jesus’ works, and of Moses and Scripture (Jn 5:32-46). In the encounter in John 8, however, the focus shifts to his own testimony.
Returning to the OP’s question, the problem lies in the apparent disconnect between what Jesus considers as credible testimony and what the Pharisees consider to be so. The Pharisees were thinking strictly in terms of human testimony, of two or more witnesses other than oneself, according to their laws (Jn 8:17, cf Deut 19:15).
Jesus, on the other hand, was making the case for why the testimony that he received was “not from man,” even if that man were John the Baptist (cf Jn 3:11-13).
You have sent messengers to John, and he has testified to the truth.
34 But the testimony I receive is not from man, but I say these things
so that you may be saved. – Jn 5:33
Jesus answered and said to them, “Even if I am testifying about
Myself, My testimony is true, because I know where I came from and
where I am going; but you do not know where I come from or where I am
going.” – Jn 8:14
Truly, truly, I say to you, we speak of what we know and testify of
what we have seen, and you people do not accept our testimony. 12 If I
told you earthly things and you do not believe, how will you believe
if I tell you heavenly things? 13 No one has ascended into heaven,
except He who descended from heaven: the Son of Man. – Jn 3:11-13
Ultimately, the testimony about Jesus rests with himself and the Father.
If I alone testify about Myself, My testimony is not true. 32 There is
another who testifies about Me, and I know that the testimony which He
gives about Me is true. – Jn 5:31-32
I am He who testifies about Myself, and the Father who sent Me
testifies about Me.” – Jn 8:18
In John 5 Jesus said that he was not alone in his testimony. In John 8 he expands on this thought, saying that “even if” he testified about himself (Jn 8:14), his testimony is true because everything that he said and did in essence constituted the testimony of the Father.
“He who sent Me is true; and the things which I heard from Him, these
I say to the world.” 27 They did not realize that He was speaking to
them about the Father. 28 So Jesus said, “When you lift up the Son of
Man, then you will know that I am, and I do nothing on My own, but I
say these things as the Father instructed Me. 29 And He who sent Me is
with Me; He has not left Me alone, for I always do the things that are
pleasing to Him.” – Jn 8:26-20