backgrounDRb: problem with saving files within the worker

in my rails app I’m using BackgrounDRb and I have problems with saving
the generated files into the temp directory within the do_work method of
worker. Despite the fact that in log the are written paths to all files,
it actually saves only the half of the files (first file, then 21st file
and then from 46 to the last one which is 98).

Here is the invocation of the worker in the controller:

MiddleMan.new_worker :class => :page_capturer_worker, :args => {
:page_address => “”,
:product_ids => @products }, :job_key => ‘page_capturer’

Any ideas?

Here is the code of the worker:

class PageCapturerWorker < BackgrounDRb::Rails
require ‘open-uri’
require ‘tempfile’

def do_work(args)
lines = []
@temppathes = []

@logger.debug "Object #{self.object_id} : #{self.class}."

page_addr = args[:page_address]
products = args[:product_ids]

products.each do |p|
  file = open(page_addr.to_s + "" + p.to_s){ |f| f.each_line {|line|

lines << line}}
tmpfile =“product_” + p.to_s)
tmpfile.puts lines.join(‘’)
@logger.debug “File saved in " + tmpfile.path + " for product” +
p.to_s + “.”
@temppathes << tmpfile.path
lines = []

MiddleMan.cache_as('pathes', 300, @temppathes)