Reopen output file on each iteration, so in case of failure previous image results should be saved