Maybe instead of using a temporary file you could benefit from one of the serveral
Cache modules so you can store Perl data and retrieve it without seeking the file up and down. I've used
Cache::Cache several times but I'm sure that there are other good modules that fit the idea.