Gold ends marginally lower, but posts monthly gain