Tempfiles

I'm trying to get Tempfiles to work but they randomly disappear. It
is very likely that I do not know how they work. This is what I want
to do...if you think there's a better and accepted approach please let
me know.

I'm parsing icalendar data. I want to fetch the data from an
uploaded .ics file or from Zimbra only once. So I need to store the
data somehow during processing then discard it later. Tempfile seems
like the thing to use. Here's my code....

def createTempFile(cal)
    temp_file = Tempfile.new("calendar")
    calendar_file = File.new(temp_file.path, "w+")
    calendar_file.puts(cal.to_ical)
    calendar_file.close
    session[:calendar_path] = temp_file.path
    logger.info "TEMPFILE: #{temp_file.path}"
end

I then pull the path from the session so I can use it in other
functions in the same controller. Sometime it disappears from the
temp directory sometimes it does not and I'm able to process it.

Am I missing something fundamental about how Tempfile works?

Thanks for your help!