fix Issue 12379 - Add toFile function which writes its first argument to a file