defer the call to os.Remove + add a condition to only remove the temp file when the -w flag is true (otherwise the file is deleted before the user can read it)
replace logger by a local function