In all cases where the plaintiff does not abandon the premises to the defendant, the court may, on written application of either party during the term when judgment is entered, order the costs recovered by the plaintiff to be setoff against the appraised value of the buildings and improvements on the land. A record of this order shall be made, and the court shall thereupon enter judgment according as the balance is in favor of one party or the other.
14 M.R.S. § 6965