Not sure if this is the case from what you've got above, but all the variables in a format have to be in scope when you
define the format, otherwise you'll simply get a load of blank lines output when you call write, even if the variables are in scope at the time of the write.
I've found the easiest way to ensure this is to define the format right after the write call - but it's not the most elegant way to do it.
Maybe it's something completely different .. not sure from what's there :)
Hope that helps a little ..
-- Foxcub