Added writefile function.