Write() done but not writing the content in existing file

Thank you, so I checked with readdir() and pwd() before running the codes.

In this case, after running the codes are still empty when I checked in linux(Ubuntu).

However, this problem is solved after ls in linux. The empty file started being written. (though have no idea why–can ls refresh linux subtly?)