Minor cleanup, use writeFileSync to avoid unfinished writes, return paths to callback
Improve tests