Issue with stream.write appending undefined to file