I've seen some strange (at least for me) behavior while using write() method in Ipython as well as Jupyter notebook:
In : f = open('test.txt','w')
In : f.write("This is the first line")
This is not something specific to IPython.
write() method returns the number of characters written.
The reason you are seeing this is because you are using an interpreter.