1st:
Don't use
lindex like that...
$text is a string, not a list (consider using
split to convert it into a list).
2nd:
Don't enclose the
file command with [] if you do not intend to make use of the return code. Currently, you are trying to execute the return code from the
file delete operation as a new command.
The
file delete command will always return an empty string, causing your script to try and execute "", which is not a valid command. This will generate an error, and script execution is terminated.
Suggested further reading:
Tcl manual page - Command substitutions