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:
Meanwhile Jesus is questioned by none other than the high priest:
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.
Jesus is seen laying down his life for his disciples in 18:8-9:
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