If, on the hearing of any cause, matter or proceeding in which perjury shall be suspected to have been committed, any paper or document produced by either party be deemed necessary to be used in the prosecution for perjury, the court may by order detain the paper or document from the party producing it, and direct that it be delivered to the district attorney.