Tu polecam uzycie polecenia: with open(tab[1], 'w')

http://effbot.org/zone/python-with-statement.htm