Improved Log file Writing. Tried to Fix the "ERROR" output.