Script has different out put when called from python then when called from bash

I am making a tool so users can sink changelogs from new releases on perforce.
A user with certain rights has to login to download those logs. I need to get the p4 OAuth URL that returns when the p4 login command is ran. This is what the code looks like in bash

p4 set P4PORT=ssl:XXXXXXXX
p4 login > XXXXXXXX/temp/url.txt 2>&1 &

and that worked just fine. The url was printed out in the url.txt file.
I load this script as a template using python and write a new file with some changes, a number here a name there. I then call this script and then read the url from the file, but when I call it from my python code using['bash','XXXXXXXXXX/'])

A file url.txt is created, but it is empty.
I blocked out the file paths and ssh domain name for privacy reasons.


When loading and making edits to the template I forgot to add new lines when building the new file.
I was doing

with open('filename') as file:

instead of

with open('filename') as file:
    file.write('blah n')