I don't see why the first function (where you only provide a picture) should not work the same way as the second one.
It looks to me that the "else if" statement in the second never is executed because an empty string (two quotes and nothing in between - I guess that's what you refer to as "double quote"?) does already trigger the if branch.
You would have to provide both functions as working Prime code (not pictures) and demo data for T and especially P which does not work with the first function but works OK with the second one.
From the file you provided it looks to me that both function create the very same file!
In case of an empty string ("") the functions create something which may look in some text editors like a space in quotes (" ") but actually in between the quotes there is a character with ASCII/ANSI code #0 (on contrary to a space which is code #32).
To create a true empty string (two double quotes and nothing in between) in the file you would have to use something like this

BTW, try...on error... just traps errors - do you experience any error when using the first version of your function?