If i do it from a normal action and an http request, all is working fine.
Do you know if it's a bug?
If you have Apache running as www-data, all files written during your HTTP requests are owned by www-data. If you use your console as your own user (so, not www-data) and you haven't set permissions such you can remove files which are owned by www-data, you cannot remove those files.
Make sure those files can be removed by your own user and you can probably remove the files.