temp.ss
#lang scheme/base

(require scheme/file)
(require scheme/contract)

(define temporary-directory (make-parameter "/tmp"))

(define (with-file next)
  (let ([name (make-temporary-file "mzcrypt~a" #f (temporary-directory))])
    (dynamic-wind
     void
     (λ () (next name))
     (λ ()
       (when (file-exists? name)
         (delete-file name))))))

(provide/contract
 [with-file (-> (-> path? any) any)]
 (temporary-directory parameter?))