Random number generation
$fwrite(file, obj); will print the memory address of the object. To print the object's addr in oct (followed by a newline), use $fwrite(file, "%o\n", obj.addr); or $fdisplay(file, "%o", obj.addr);

There are also the system display tasks $fwriteo and $fdisplayo which have the default formatting as oct.

This is all well document in IEEE Std 1800-2012 &sect; 21 Input/output system tasks and system functions, as well as previous version of SystemVerilog and all version of Verilog (IEEE Std 1364) in there respected sections on system task/function.