optimized file logging (writes only periodicaly)