Wrap your code in a VBS script and point your task to this file
VBscript's run method can execute batch commands in a hidden window, if you set "intWindowStyle" to 0.
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
Put this code into your HiddenTask.vbs file.
Set wShell = CreateObject ("Wscript.Shell")
wShell.Run "cmd /c copy /Y nul D:\keepalive.txt", 0
I successfully tested your example. It creates a new empty file just like it should. Of course without displaying any window.
Read this SO question regarding your issue that it's not working when used as scheduled task. Grant your job administrator rights and set the "start in" folder. Also, check the event log for this task.
Additionally I made some screenshots. Maybe you are able to find the difference to your setup.
If you're facing an issue after following the instructions here, please read the comments below, the issue may be the file name or path.