The fragmentation of the file is unavoidable (as far as I know). :-(
You could minimise it by creating bigger blocks for the file, keep writing data to the file untill the block is full then creating another big (empty) block for the file and filling it etc. :-)
Another thing that you could do is do a sort of log rotate thing. When creating the file create it with a date imbeded in the name (YYYY-MM-DD is best that way 'dir' will put them in order) write you data to the file close it and don't use it again. :-)