Create file if file doesnt exist

It was actually throwing error if the file did not existed while calling the writeFile(); It creates the file, 
If the file already exists it appends the data (as we are opening the file in append mode);

Thanks