function evaluation and writing to file