Section 48. An officer directed to make an attachment of personal property may, if the writ bears an endorsement signed by a justice, associate justice or special justice of the court in which the action is commenced and stating that, in his opinion, the appointment of a keeper is necessary, appoint a keeper of such property at or after the time of making such attachment. No writ shall be so endorsed unless the plaintiff, in support of his application for said appointment, shall first have filed an affidavit stating the facts which require such appointment. The officer, if necessary, may appoint a keeper of personal property which has been taken on execution. In either of the aforesaid cases he shall, upon the written request of the defendant, remove such property or the keeper without unreasonable delay. Costs in an action in which a keeper has been appointed shall be at the discretion of the court.