@param: tmpdir: Optional, specify directory where temp file will be created