Может это? Его сложно протестировать без чего-либо, чтобы запустить его:
# read the linesinfile list, but store a mini list with the original positions of lines (index) and original line (value)
x = [[index, value] for index, value in enumerate(linesinfile)]
# use the random library
import random
# make a new list from x, but subtract or add a random number between -5 and +5 to the index values (this will be used to reorder the lines in file)
y = [[i[0] + random.randrange(-5, 5, 1), i[1]] for i in x]
# sort the list, y, by the new index values
# as the index is an integer, there could be clashes (duplicates in index value)
# either fix those by converting to float or use a float random number to start with, or just let the list sort as python defaults to
y.sort(key=lambda x: x[1])
#print the original lines in the new order.
for k in y:
print(k[1])