it was added to keep empty Applications folder when --keep-keychains option is used. The reason is:  when new appum session without --keep-keychains, i.e. "node ." is ran after "node . --keep-keychains" session, it will remove the Library/Keychain and other directories only if  Application directory is present in simulator. So if this piece of code is absent, appium will not detect that it requires removing Library/Keychain directory and will only clear it when testing session is over.