Avoid big concatenation in memory, write into file directly