Fixed encoding problem redirecting output to file