Nextflow is designed in such a way that you do need to organise your intermediate files in a directory structure.
For three reasons:
1) Simplify your work: think in term of files, not paths or directories;
2) Avoid race conditions when your jobs are executed in parallel manner;
3) Allowing you to resume the pipeline execution from the last successful executed if it stops for any reason.
So, you are right. You don't have to use the ${dir} variable to force a process to write the files in that folder.
If you need to copy some result in a specify place you can do that outside the process scope, for example:
myDir = file(params.folder)
read.subscribe { it.copyTo(myDir) }
Read more about copying files here:
Also note, the usage of the params.folder variable. I've changes so the "./" string is assigned to it, then it is converted to a file object, so that you can create a directory if missing. Anyway variable in the params "scope" can be overridden by specifying them on the pipeline command line. For example:
nextflow run <script> --folder /some/other/path
Hope this helps.
Cheers,
Paolo