Fixed writefile and append file