Fixed string length counting when writing to file