He said this to show the kind of death by which Peter would glorify God. After saying this, Jesus said to Peter, "Follow me."
Peter turned around and saw the disciple whom Jesus loved following them. This was the one who had leaned against Jesus at the meal and asked him, "Lord, who is going to betray you?"
References for John 21:20
When Peter saw this disciple, he said to Jesus, "Lord, what about him?"
Jesus replied, "If I want him to remain until I come, what difference does that make to you? You must follow me."
Therefore, the word spread among the brothers and sisters that this disciple wouldn't die. However, Jesus didn't say he wouldn't die, but only, "If I want him to remain until I come, what difference does that make to you?"
This is the disciple who testifies concerning these things and who wrote them down. We know that his testimony is true.
Jesus did many other things as well. If all of them were recorded, I imagine the world itself wouldn't have enough room for the scrolls that would be written.