Java Robot Class to get it to automatically navigate the uigetfile() menus as if you had clicked the appropriate keys yourself.
But really it would be so much easier to rewrite your second file slightly so that it received the file name as an input parameter, possibly adding a small extra function to invoke uigetfile() and call that revised routine if you still need to support the prompting for some reason.