Your script should work without any problem but....
You are trying to rename .ldf file which is data base log file... if I am not mistaken...
You can rename the file while db is active... so you have to kill all the users from the db and detach it using sp_detachdb procedure then rename it...
I don't understand why you want to rename .ldf file...
MohammedU
Microsoft SQL Server MVP