Excretion of monovalent and divalent ions in sharks
The main reason seems to be a mechanism to save water and allow the excretion of higher concentrations of the ions. See the image (from here):



The urine enters the glomeruli at a relatively low rate and with a low magnesium concentration. The paper cited below mentions a concentration of 1.5mM. First organic compounds as glucose are recovered actively, water follows the molecules passively. Then more ions as Ca$^{2+}$ enter in the proximal segment II. In the distal segment finally sodium and chloride are actively transported out while water passively leaves the segment. The divalent ions (magnesium, calcium) are left in high concentrations (the paper below says that the Mg concentration is now around 130mM). This helps concentrating these ions for excretion while loosing as little water as possible at the same time. Sodium and chloride are actively regulated in the gills.

For a short overview, see the link at the image above, for a detailed view, have a look at the following publication: "Kidneys sans glomeruli".