In John 18, the author weaves together an account of Peter's denial and a questioning of Jesus before Annas. It's very well done and seems rather more complex from a literary standpoint. But what does John gain by telling the stories this way?
The interviewing of the two narratives provides a comparison between the character of Jesus and that of Peter. This functions in a couple ways:
First, by interweaving the two narratives, John puts into sharp contrast Jesus' ability to withstand questioning and Peter's inability. Peter forsakes the truth when questioned even by a servant girl:
The other disciple, who was known to the high priest, came back, spoke to the servant girl on duty there and brought Peter in.
“You aren’t one of this man’s disciples too, are you?” she asked Peter.
He replied, “I am not.” (18:16-17)
Meanwhile Jesus is questioned by none other than the high priest:
Meanwhile, the high priest questioned Jesus about his disciples and his teaching.
“I have spoken openly to the world,” Jesus replied. “I always taught in synagogues or at the temple, where all the Jews come together. I said nothing in secret. Why question me? Ask those who heard me. Surely they know what I said.” (18:19-21)
One recalls the earlier statement in John 3:21, that "whoever lives by the truth comes into the light, so that it may be seen plainly that what they have done has been done in the sight of God." Jesus is portrayed as one not afraid of his accusers, nor afraid to come into the light. He has always taught in public and he denies nothing. Peter, perhaps afraid after having drawn his sword on the high priest's servant, denies Jesus.
Second, the interviewing of the narratives provides John the opportunity to compare Jesus as the good shepard with Peter as the hired hand.
I am the good shepherd. The good shepherd lays down his life for the sheep. The hired hand is not the shepherd and does not own the sheep. So when he sees the wolf coming, he abandons the sheep and runs away. Then the wolf attacks the flock and scatters it. The man runs away because he is a hired hand and cares nothing for the sheep. (10:11-13)
Jesus is seen laying down his life for his disciples in 18:8-9:
Jesus answered, “I told you that I am he. If you are looking for me, then let these men go.” This happened so that the words he had spoken would be fulfilled: “I have not lost one of those you gave me.”
Meanwhile, Peter's actions are that of the hired hand. While he fights at first, ultimately he flees when the wolf comes. This reading is confirmed by Jesus' threefold admonition to Peter in John 21 to feed and take care of Jesus' sheep, corresponding to Peter's threefold denial here in John 18.
Bible quotations from NIV