Lua script with Log

Hi, i have a problem with my code.
first I write in the serial port and I collect the answer in Result. I want all Result in a file as a log.

This is my script. Thanks.

port= “/dev/ttyATH0”
serialout= io.open(port,“w”)
serialin= io.open(port,“r”)
while true do
serialout:write(“½”…"@")
Result= LeerSerial()
end

function LeerSerial()
while true do

		serialData= serialin:read();serialin:flush()	

		if string.len(serialData)>0 then
			serData = serialData
		end

		if  string.len(serialData) == 0 then
			return serData
		end

	end

end

file.write and file.append is what you are looking for