handling errors on writeFiles with retries