Need to generate .txt with temperature info

Hey guys I’m trying to get my phidget sensors to generate a document with the temp results in it,


tell application "PhidgetsOSA"
	
	get library version
	set thisScript to path to me
	
	if first phidget temperature sensor exists then
		set phid to the first phidget temperature sensor
	else
		set phid to make the phidget temperature sensor
		
		tell phid to make new attach handler with properties {script file:thisScript}
		tell phid to make new detach handler with properties {script file:thisScript}
		tell phid to make new temperature change handler with properties {script file:thisScript}
		
		open phid wait 1000 --allows application 1 second to attach to the  Phidget
	end if
	
	if phid is attached then
		
		tell phid
			
			set tName to name
			log tName & " is attached"
			
			set tSerialNumber to serial number
			log "Serial Number: " & tSerialNumber
			
			set tVersion to version
			log "Version: " & tVersion
			
			set tInputCount to (temperature sensor count)
			log " # Sensors: " & tInputCount
			
			set ambTemp to ambient temperature
			log "Ambient Temperature: " & ambTemp
			
			set every temperature sensor's sensitivity to 0.1
			
			repeat with sensorIndex from 1 to count temperature sensor
				
				log ""
				
				set tempMin to temperature sensor sensorIndex's minimum temperature
				log "Sensor " & sensorIndex & "'s minimum temperature is " & tempMin
				
				set tempMax to temperature sensor sensorIndex's maximum temperature
				log "Sensor " & sensorIndex & "'s maximum temperature is " & tempMax
				
				--TemperatureSensor IR does not support potential
				if device id is not Phidget_TemperatureSensor_IR then
					set pot to temperature sensor sensorIndex's potential
					log "Sensor " & sensorIndex & "'s potential is " & pot
					
					set potMin to temperature sensor sensorIndex's minimum potential
					log "Sensor " & sensorIndex & "'s minimum potential is " & potMin
					
					set potMax to temperature sensor sensorIndex's maximum potential
					log "Sensor " & sensorIndex & "'s maximum potential is " & potMax
				end if
			end repeat
			
			set countme to 0
			log "
			
		

Outputting temperature information 2 times at 10 second intervals"
			repeat with i from 2 to 10
				
				log ""
				repeat with sensorIndex from 1 to count temperature sensor
					
					set temp to temperature sensor sensorIndex's temperature
					if temp is not missing value then
						log "Sensor " & sensorIndex & "'s temperature is " & temp & " degrees celsius"
					else
						log "Sensor " & sensorIndex & "'s temperature is missing value"
					end if
				end repeat
				
				
				delay 1
			end repeat
			
			
			
			log "
Freeing lock on Phidget and exiting PhidgetsOSA"
			delete attach handlers of phid
			delete detach handlers of phid
			delete temperature change handler of phid
			close phid
			delete phid
			quit
			
		end tell
		
		
	else
		log "Couldn't attach to PhidgetTemperatureSensor"
		display dialog "Couldn't attach to PhidgetTemperatureSensor"
	end if
	
end tell

using terms from application "PhidgetsOSA"
	
	on attach phid
		say "attach " & (name of phid)
	end attach
	
	on detach phid
		say "detach " & (name of phid)
		
		--uncomment the following code to free the Phidget object upon it's detach event
		--delete attach handlers of phid
		--delete detach handlers of phid
		--delete temperature change handler  of phid
		
		--close phid
		--delete phid
		--quit
	end detach
	
	--runs whenever the temperature change is greater than the sensitivity
	on temperature changed ind to temp on phid
		log "Sensor " & (ind as text) & "'s temperature changed to " & (temp as text)
		--insert code
	end temperature changed
	
	
end using terms from


right now this script works great and gives me the 4 sensors temp data in the messages window of script editor, i need that same info to go to a .txt on my desktop

First time you run this, it’ll make a file called “my data file.txt” on the desktop, and add a line of data to it.
Run it again, and it’ll add a second line of data.

It’ll let you do Mac or Unix style line endings, depending on what you want to use the file for.

-- Make a file as needed, and append a line of data to end

------------------
set destfolder to (path to desktop as string) --& "result:"


set filesname to "my data file"
set alineofdata to "11/14/14	12:05	9781
"


set alineofdata to ((current date) as text) & "
"


------------------
---------------------------------------------------------------------- Pick a line ending style to use in the file. UNIX (eg sed) expects newlines,
set toUNIX to 0 -- line ending styles  \n for UNIX, \r for mac
set toMac to 1
set linendingstyletouse to toMac --------------------------- Pick it here
----------------------------------------------------------------------
set dst to destfolder

WriteAFile(alineofdata, dst, filesname, toMac)
------
------
on WriteAFile(textform, dst, subfldrnam, MacorUNIX)
	
	
	set writeit to true
	set filpath to dst & subfldrnam & ".txt"
	
	set thetext to ""
	set thetext to MakeLineEndingsMacOrUNIX(textform, MacorUNIX) -- 0 for UNIX style line endings, 1 for Mac style line endings	
	try
		set fileID to open for access file filpath with write permission
	on error result
		display dialog result -- let em know whats wrong
		set writeit to false
		try
			close access file filpath -- let this fail silently
		end try
	end try
	if writeit then
		--set eof file filpath to 0
		write thetext to file filpath as string starting at eof -- <--- specify the format
	end if
	try
		close access file filpath -- let this fail silently
	end try
	return writeit
end WriteAFile
------
------
on MakeLineEndingsMacOrUNIX(thetext, whichway)
	set toUNIX to 0
	set toMac to 1
	set temlst to {}
	
	if whichway is equal to toMac then
		set lookfor to "
"
		set replace to "
"
	else -- toUNIX
		set lookfor to "
"
		set replace to "
"
	end if
	
	set text item delimiters to lookfor
	set temlst to every text item of thetext
	set text item delimiters to replace
	set filteredtext to every item of temlst as string
	set text item delimiters to ""
	return filteredtext
	
end MakeLineEndingsMacOrUNIX
------
------