add writeFile to retry logic
refactor