in reply to umask with 0666

Instead of
  1. Get and change umask.
  2. Create file
  3. Reset umask.
You could
  1. Create file
  2. Change permissions

If you do so, there will be a short period where the file will have a more restrictive mask than desired. I don't know if that matters in your case.