Please read the manual page for close(). Just because you closed the file doesn't mean your data is on disk.
As for rename, your file gets renamed _atomically_ just fine. However, if you don't _commit_ your writes (make the changes durable, call fsync), the renamed file will have zero size.
This is not a file system problem, but an application problem.