Fix security issue when writing log file