Refactor file creation via sudo into a single method