Replace all those SendKeys with one:
I actually did pretty much the same save I have a separate script that that lives for 2 minutes who's sole purpose in life is to kills off that popup window. In the calling application I call Win32::Process::Create as a detached_process just before causing the window to popup.
p2:started, on loop look for window
p1:hang on output
p2:found window, click yes (till yes is available)