Moved check for calledback inside writeFile