Test writing to file