Any surplus of the proceeds of sale of mortgaged premises, after satisfying the principal debt in the mortgage, with interest and costs, shall be rendered to the owner of the premises at the time of sale. Until the surplus is so rendered, the officer making the sale shall not be discharged upon the record of the court to which the sale is returnable.