Can you post the code? We can't really debug it if we don't know what it looks like.
PS: Since you're new here you should have a look at
How (Not) To Ask A Question
Update: Other details like the operating system, filesystem (eg NFS), etc could be helpful too. Does the file get created? Does it have some but not all of the data?