writes output to file (retry)