The court, in its discretion, may require any person, before he receives his portion of the proceeds of the sale to give such security as it directs, to the state, or the county treasurer, who shall hold it for the use and benefit of the persons interested, or to such parties or other persons as it prescribes, to refund the same, or a portion thereof, with interest, if it thereafter appears that he was not entitled thereto.
N.Y. Real Prop. Acts. Law § 971