replace create_dir with equivalent os.makedirs

also fix race condition in user-only permission setting