in reply to writing to log file
I'm confused by the lack of a question mark in your question. It would be easier to answer whatever your question is if you actually ask it.
(And, use 3-argument open unless you can guarantee you will never have pathological $log filenames...)