I am very new to Python. I know that this has already been asked, and I apologise, but the difference in this new situation is that spaces between strings are not equal. I
replace your first bit with this. it's not super pretty but it will give you a csv format.
with open('coord') as infile, open('coordv', 'w') as outfile:
for line in infile:
outfile.write(" ".join(line.split()).replace(' ', ','))
outfile.write(",") # trailing comma shouldn't matter
if you want the outfile to have everything on different lines you could add
outfile.write("\n") at the end of the for loop, but i dont think your code that follows this will work with it like that.