updated write_task to create a directory if one doesn't exist