Added write to file function