Function to write cookie to file