Templater , to generate one imput in one query

I am planning to create a template in Obsidian, which I will call ‘Query’. This template will be designed to generate a query based on an input variable. To achieve this, I need to place the file in a specific folder and I want to use only one file that automatically regenerates every time I execute the query. For this purpose, I have considered using the Templater plugin: after activating it, the system should check if the file already exists; if yes, it will delete it and create a new one. However, I am encountering difficulties in making this process work and am seeking help to resolve the issue.

<%* 
const file = app.vault.getAbstractFileByPath("Qw");
const fmfile = "001-Agrati_PRM/Report-Meeting/Query/Query-week"; 
const fmweek = await tp.system.prompt("Settimana da controllare:"); 
if (!tp.file.exists(fmfile) == true) { await app.vault.trash(fmfile, true);}
await tp.file.move(fmfile);
-%>
---
cssclasses:
  - whiteRed-rounded
  - wideTable
  - customname
---
### Note Processed in Week <%fmweek%>

```dataview
LIST (data)
WHERE (file.cday.weekyear = <%fmweek%> AND file.cday.year = 2023)
SORT file.outlinks.file ASC

The problem is that the file is not deleted when it is present in the folder, and therefore the process gets stuck, without generating the new “Query” file.