I'm not sure I understand why you say "
I want the excel file storing part outside the case structure".
From the rest of your description, it sounds like you want to write to file only if something is true. That means that you put the write to file function
inside the TRUE case.
You can pass the file refnum into the case and back out again, if you need to. Pass it straight thru in the FALSE case, and thru the WRITE FILE function in the TRUE case.