Add local output for number of iterations

As a best practice and the "standard" way of closing a stream, is to close it in the finally block.