added encoding for metrics file write