This code works for me:
user_name_in =input("gets Input")
fname = user_name_in
f = input()
ufile = open(fname,"w")
while True:
f=input(answer)
ufile.write(f)
Some considerations:
I don't see where answer is declared, neither python interpreter see :P, maybe you forgot to paste this part of the code or indeed this was the error?
I don't understand why you assign the name of the file to a variable and then re-assign to another one.
How do I stop writing to the file? The only way I found was Ctrl-C, which doesn't sound ideal.
To reassure the file is being closed you can replace it with a with open(fname) as ufile block
with open(fname, 'w') as ufile: ufile.write(f)?ufile.close()and see if that fixes it.flushthe file. always use thewithto handle files.