Like madewokherd suggested, it would be faster if you started closer to the end of your file... then work backwards in chunks until you have accumulated 5 matches. Of course, this is slightly complicated and requires nested loops and keep track of your position.
It may be easier to simply break your urls file up into multiple files, by month or something.
- Raccoon