OK, I now see it's not an infinite loop, it's just going through the 1+2+3+...+631 Rounds cycle, which wasn't my intent. This code is processing a file with only about a total of 30 instances of html, pdf, or txt references, so I was expecting the @output array to have only about 30 elements. The other 600-ish elements are duplicates. How do I keep each file reference from going into the @output array more than once?