Throw error in writeFIle if data is not buffer or string