Using the with statement for the stdout redirect and the lock file.