Use write method instead of puts for file output.